﻿@namespace MatBlazor
@implements IDisposable
@inject IMatPortalService PortalService


@foreach (var item in PortalService.GetItems())
{
    <CascadingValue @key="@item.Id" Value="@item">
        <MatComponentHost Type="@item.ComponentType" Attributes="@item.Attributes"></MatComponentHost>
    </CascadingValue>
}


@code
{
    protected override void OnInitialized()
    {
        base.OnInitialized();
        PortalService.StateChanged += OnStateChanged;
    }

    private void OnStateChanged(object sender, EventArgs e)
    {
        InvokeAsync(() => { this.StateHasChanged(); });
    }

    public void Dispose()
    {
        PortalService.StateChanged -= OnStateChanged;
    }
}